/*
 * MIT License
 *
 * Copyright (c) 2024-2048 冰羽
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package cn.star.framework.util;

import java.util.HashSet;
import java.util.Set;

/**
 * 关键字<br>
 *
 * @author zhaoweiping
 *     <p style='color: red'>Created on 2024-09-23 11:06:00
 * @since 3.0.0
 */
public class Keyword {
  private static final Set<String> SET = new HashSet<>(50);

  public Keyword() {
    this.register("abstract");
    this.register("assert");
    this.register("boolean");
    this.register("break");
    this.register("byte");
    this.register("case");
    this.register("catch");
    this.register("char");
    this.register("class");
    this.register("const");
    this.register("continue");
    this.register("default");
    this.register("do");
    this.register("double");
    this.register("else");
    this.register("enum");
    this.register("extends");
    this.register("final");
    this.register("finally");
    this.register("float");
    this.register("for");
    this.register("goto");
    this.register("if");
    this.register("implements");
    this.register("import");
    this.register("instanceof");
    this.register("int");
    this.register("interface");
    this.register("long");
    this.register("native");
    this.register("new");
    this.register("package");
    this.register("private");
    this.register("protected");
    this.register("public");
    this.register("return");
    this.register("short");
    this.register("static");
    this.register("strictfp");
    this.register("super");
    this.register("switch");
    this.register("synchronized");
    this.register("this");
    this.register("throw");
    this.register("throws");
    this.register("transient");
    this.register("try");
    this.register("void");
    this.register("volatile");
    this.register("while");
  }

  /**
   * 判断Java关键字
   *
   * @param str 关键字
   * @return 是否关键字
   */
  public static boolean isKeyword(String str) {
    return SET.contains(str);
  }

  @SuppressWarnings("all")
  public Keyword register(String keyword) {
    SET.add(keyword);
    return this;
  }
}
